//
//  ScrollView.m
//  Test
//
//  Created by mac on 2017/8/24.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "ScrollView.h"

@interface ScrollView ()

@end

@implementation ScrollView

+(Class)layerClass{
    
    return [CAScrollLayer class];
    
}

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
    }
    
    return self;
}

-(void)setUp{
    
    self.layer.masksToBounds = YES;
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];
    [self addGestureRecognizer:pan];
}

-(void)panAction:(UIPanGestureRecognizer *)pan{
    
    CAScrollLayer *layer = (CAScrollLayer *)self.layer;
    CGPoint offset = self.bounds.origin;
    //手势接触的点在self中的位置
    offset.x -= [pan translationInView:self].x;
    offset.y -= [pan translationInView:self].y;
    [layer scrollToPoint:offset];
    [pan setTranslation:offset inView:self];
}
@end
